// https://nuxt.com/docs/api/configuration/nuxt-config
import { $fetch } from 'ofetch'

async function getRemoteRoutes() {
  const slugs = await $fetch('https://xingapi.com/api/v1/curd/xm-articles?skip=0&limit=99')
  const articles = slugs.data.items
  return articles.map((article: any) => `/articles/${article._id}`)
}

const articlesRoutes = await getRemoteRoutes()
const allRoutes = ['/', '/about/', '/aos', '/full-page', ...articlesRoutes]

export default defineNuxtConfig({
  compatibilityDate: '2024-11-01',
  devtools: { enabled: true },
  nitro: {
    prerender: {
      routes: allRoutes // 预渲染路径
    }
  },
  vite: {
    build: {
      minify: 'terser',
      terserOptions: {
        compress: {
          drop_console: true, // 删除 console
          drop_debugger: true // 删除 debugger
        }
      }
    }
  },
  runtimeConfig: {
    public: {
      baseUrl: process.env.NUXT_BASE_URL,
      amapKey: process.env.NUXT_AMAP_KEY,
      amapCode: process.env.NUXT_AMAP_CODE
    }
  },
  app: {
    // cdnURL: 'https://cdn.yoursite.com' // 静态资源加速路径
    head: {
      title: 'Xing-api-nuxt3',
      htmlAttrs: { lang: 'zh-CN' },
      charset: 'utf-16',
      viewport: 'width=device-width, initial-scale=1, maximum-scale=1',
      link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
    }
  },
  modules: ['@nuxtjs/tailwindcss', '@element-plus/nuxt', 'nuxt-swiper', 'nuxt-echarts'],
  features: {
    inlineStyles: false // 移除源代码内联style
  },
  experimental: {
    renderJsonPayloads: false // 不使用 window.__NUXT__ 注入 JSON
  }
})
